package com.sunbo509.www.gridview;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.GridView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;


import com.jaeger.library.StatusBarUtil;


import java.util.ArrayList;
import java.util.HashMap;

import cn.qqtheme.framework.picker.OptionPicker;


public class MainActivity extends AppCompatActivity {
    private GridView gv;
    private int[] pic = {
            R.mipmap.ic_launcher_round,
            R.mipmap.ic_launcher_round,
            R.mipmap.ic_launcher_round,
            R.mipmap.ic_launcher_round,
            R.mipmap.ic_launcher_round,
            R.mipmap.ic_launcher_round,
            R.mipmap.ic_launcher_round,
            R.mipmap.ic_launcher_round,
            R.mipmap.ic_launcher_round,
    };
    private String[] word = {
            "1", "2", "3", "4", "5", "6", "7", "8", "9"
    };

    ArrayList<HashMap<String, Object>> resource = new ArrayList<HashMap<String, Object>>();
     private OptionPicker picker;
     private ArrayList<String>list=new ArrayList<>();
     private Button btn;
     private TextView tv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

//状态栏着色
        StatusBarUtil.setColor(MainActivity.this, getResources().getColor(R.color.purple),0);
        gv = (GridView) findViewById(R.id.gv);
        btn=(Button)findViewById(R.id.button3);
        tv=(TextView)findViewById(R.id.tv);

        for (int i = 0; i < pic.length; i++) {
            HashMap<String, Object> map = new HashMap<String, Object>();
            map.put("pic", pic[i]);
            map.put("word", word[i]);
            resource.add(map);
        }

        for(int i=0;i<word.length;i++){
            list.add(word[i]);
        }

        SimpleAdapter adapter = new SimpleAdapter(this,
                resource,
                R.layout.item,
                new String[]{"pic", "word"},
                new int[]{R.id.pic, R.id.word});
        gv.setAdapter(adapter);
        gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(MainActivity.this, word[position], Toast.LENGTH_SHORT).show();
                Intent intent=new Intent(MainActivity.this,LayoutActivity.class);
                startActivity(intent);
            }
        });

        picker=new OptionPicker(this,list);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() {
                    @Override
                    public void onOptionPicked(int index, String item) {
                        tv.setText(item);
                        Toast.makeText(getApplicationContext(),item,Toast.LENGTH_SHORT).show();
                    }
                });
                picker.show();
            }
        });
         picker.setTextColor(getResources().getColor(R.color.colorAccent));
         picker.setTextSize(20);
         picker.setLabel("厘米");
         picker.setCanceledOnTouchOutside(true);
//        picker.setShadowColor();
         picker.setTitleText("很不错的框框");
         picker.setTitleTextSize(20);
//        picker.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
//         picker.setHeight(300);设置整个框框的大小
         picker.setCancelText("取消");
         picker.setSubmitText("提交");

    }
}




